package com.shqcjd.preinstallmobile.ui.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.annotation.Nullable;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.shqcjd.preinstallmobile.R;
import com.shqcjd.preinstallmobile.model.pojo.PlayBackBean;
import com.shqcjd.preinstallmobile.ui.activity.MoreContentActivity;
import com.shqcjd.preinstallmobile.ui.activity.preview.PreImageActivity;
import com.shqcjd.preinstallmobile.ui.activity.preview.VideosActivity;
import com.shqcjd.preinstallmobile.util.UIUtils;

import java.util.List;

public class PlaybackAdapter extends BaseQuickAdapter<PlayBackBean.ItemsBean,BaseViewHolder> {
    private Context context;
    private int tId;
    public PlaybackAdapter(@Nullable List<PlayBackBean.ItemsBean> data, Context context, int tId) {
        super(R.layout.item_playback, data);
        this.context = context;
        this.tId = tId;
    }

    @Override
    protected void convert(BaseViewHolder helper, PlayBackBean.ItemsBean item) {
        helper.setText(R.id.tv_item_playback_name, (helper.getAdapterPosition()+1)+". "+item.equipment_name);
        helper.setText(R.id.tv_item_playback_kks, "KKS: "+item.kks);
        helper.setText(R.id.item_playback_time, "巡检时间: "+(item.record_time==null?"----":item.record_time));
        TextView textView = helper.getView(R.id.tv_item_playback_state);
        TextView tvTip = helper.getView(R.id.tv_item_playback_tip);

//        if(item.status.equals("正常")){
//            textView.setTextColor(Color.parseColor("#598ae9"));
//            tvTip.setVisibility(View.GONE);
//        }else{
//            textView.setTextColor(Color.parseColor("#ef3131"));
//            tvTip.setVisibility(View.VISIBLE);
//            String str = "";
//            for(int i=0; i<item.info.size(); i++){
//                str = str+item.info.get(i)+(i==item.info.size()-1?"":"\n");
//            }
//            tvTip.setText(str);
//        }

        RecyclerView mRecyclerView = helper.getView(R.id.rv_item_playback);
        mRecyclerView.setLayoutManager(new GridLayoutManager(context,3));
        PlaybackItemAdapter playbackItemAdapter = new PlaybackItemAdapter(item.img, context);
        mRecyclerView.setAdapter(playbackItemAdapter);

        playbackItemAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                if(adapter.getData().size()>9&&position==8){
                Intent it = new Intent(context, MoreContentActivity.class);
                it.putExtra("eId", item.id);
                it.putExtra("tId", tId);
                context.startActivity(it);
                }else{
                    if(UIUtils.getFormatName((String)adapter.getData().get(position)).equals(".mp4")){
                        Intent it = new Intent(context, VideosActivity.class);
                        it.putExtra("url", (String)adapter.getData().get(position));
                        it.putExtra("name", "视频详情");
                        context.startActivity(it);
                    }else{
                        Intent it = new Intent(context, PreImageActivity.class);
                        it.putExtra("url", (String)adapter.getData().get(position));
                        it.putExtra("name", "图片详情");
                        context.startActivity(it);
                    }

                }
            }
        });
    }

}
